#region Copyright(c) 2006 ZO, All right reserved.
// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1.  Redistribution of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//   2.  Redistribution in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//   3.  The name of the author may not be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
#endregion


#region Using directives

using System;
using System.Collections;
using System.Windows.Forms;
using ArgumentNullException= ZO.SmartCore.Core.ArgumentNullException;

#endregion

namespace ZO.SmartCore.Windows.Forms.OptionControls
{
	/// <summary>
	/// Represents a node of a Tree Option Dialog. 
	/// </summary>
	public sealed class SmartTreeOptionNodes : IList, ICollection, IEnumerable
	{

		#region Constructors


		/// <summary>
        /// Initializes a new instance of the <see cref="SmartTreeOptionNodes"/> class.
		/// </summary>
		internal SmartTreeOptionNodes(TreeNodeCollection nodes)
		{
			if (nodes == null)
			{
				throw new ArgumentNullException("nodes");

			}
			this.InnerNodes = nodes;
		}

		/// <summary>
        /// Initializes a new instance of the <see cref="SmartTreeOptionNodes"/> class.
		/// </summary>
		internal SmartTreeOptionNodes(TreeNodeCollection nodes, SmartTreeOption dialog)
		{
			if (nodes == null)
			{
				throw new ArgumentNullException("nodes");

			}
			this.InnerNodes = nodes;

			this.Dialog = dialog;

			parentNode = true;
		}
		#endregion

		#region Destructor

		#endregion

		#region Fields
		private TreeNodeCollection _InnerNodes;

		private SmartTreeOption Dialog;

		private bool parentNode;

		#endregion

		#region Events

		#endregion

		#region Operators

		#endregion

		#region Properties




		/// <summary>
		/// Gets or sets the inner nodes.
		/// </summary>
		/// <value>The inner nodes.</value>
		internal TreeNodeCollection InnerNodes
		{
			get { return _InnerNodes; }
			set { _InnerNodes = value; }
		}


        /// <summary>Gets the total number of <see cref="SmartTreeOptionNode"></see> objects in the collection.</summary>
        /// <returns>The total number of <see cref="SmartTreeOptionNode"></see> objects in the collection.</returns>
		public int Count
		{
			get
			{
				return InnerNodes.Count;
			}
		}

		/// <summary>Gets a value indicating whether the collection is read-only.</summary>
		/// <returns>true if the collection is read-only; otherwise, false. The default is false.</returns>
		public bool IsReadOnly
		{
			get
			{
				return InnerNodes.IsReadOnly;
			}
		}



		#endregion

		#region Methods

		/// <summary>
		/// Adds a new tree node with the specified label text to the end of the current tree node collection.
		/// </summary>
		/// <param name="text">The label text displayed by the <see cref="SmartTreeOptionNode"></see>.</param>
		/// <returns>
		/// A TreeOptionNode that represents the tree node being added to the collection.
		/// </returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public SmartTreeOptionNode Add(string text)
		{
			SmartTreeOptionNode node = new SmartTreeOptionNode(text);
			this.Add(node);

			return node;
		}




		/// <summary>
		/// Adds a previously created tree node to the end of the tree node collection. 
		/// </summary>
		/// <param name="node">The TreeNode to add to the collection.</param>
		/// <returns>The zero-based index value of the TreeNode added to the tree node collection.</returns>
		public int Add(SmartTreeOptionNode node)
		{
			if (node != null)
			{
				int index = this.InnerNodes.Add(node);


				if (parentNode)
				{
					Dialog.OptionTreeView.SelectedNode = node;
					Dialog.OptionTreeView.Select();

				}

				return index;

			}

			return -1;
		}

		/// <summary>Adds an array of previously created tree nodes to the collection.</summary>
		/// <param name="nodes">An array of <see cref="SmartTreeOptionNode"></see> objects representing the tree nodes to add to the collection. </param>
		/// <exception cref="T:System.ArgumentException">nodes is the child of another <see cref="T:System.Windows.Forms.TreeView"></see>.</exception>
		/// <exception cref="T:System.ArgumentNullException">nodes is null.</exception>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
		public void AddRange(SmartTreeOptionNode[] nodes)
		{
			if (nodes != null)
			{
				foreach (SmartTreeOptionNode var in nodes)
				{
					this.Add(var);
				}
			}

		}

		/// <summary>Removes all tree nodes from the collection.</summary>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
		public void Clear()
		{
			this.InnerClear(InnerNodes);
		}


		private void InnerClear(TreeNodeCollection treeCollection)
		{
			if (treeCollection == null) return;

			int treeCollectionCount = treeCollection.Count;
			for (int index = treeCollectionCount; index >= 0; --index)
			{
				TreeNode node = treeCollection[index];

				treeCollection.Remove(node);
				if (parentNode)
				{
					if (node is SmartTreeOptionNode)
					{
						SmartOptionPage control = ((SmartTreeOptionNode)node).OptionPage;
						if (Dialog.OptionPanel.Controls.Contains((control)))
						{
							Dialog.OptionPanel.Controls.RemoveAt(0);
						}
					}
				}
				this.InnerClear(node.Nodes);
			}

		}





		/// <summary>
		/// Remove the tree node item with specified config name
		/// </summary>
		/// <param name="name"></param>
		public void Remove(string name)
		{
			this.InternalRemove(InnerNodes, name);
		}

		/// <summary>
		/// Remove tree node item with specified name
		/// </summary>
		/// <param name="treeCollection">The tree collection.</param>
		/// <param name="name">The nameo of the node to remove.</param>
		private void InternalRemove(TreeNodeCollection treeCollection, string name)
		{
			if (treeCollection == null) return;

			int treeCollectionCount = treeCollection.Count;
			for (int index = treeCollectionCount; index >= 0; --index)
			{
				TreeNode node = treeCollection[index];

				if (string.Equals(node.Text, name))
				{
					InnerNodes.Remove(node);
					if (Dialog != null)
					{
						if (node is SmartTreeOptionNode)
						{
							SmartOptionPage control = ((SmartTreeOptionNode)node).OptionPage;
							if (Dialog.OptionPanel.Controls.Contains((control)))
							{
								Dialog.OptionPanel.Controls.RemoveAt(0);
							}
						}
					}
					break;
				}
				this.InternalRemove(node.Nodes, name);
			}
		}


		/// <summary>Determines whether the specified tree node is a member of the collection.</summary>
		/// <returns>true if the <see cref="SmartTreeOptionNode"></see> is a member of the collection; otherwise, false.</returns>
		/// <param name="node">The <see cref="SmartTreeOptionNode"></see> to locate in the collection. </param>
		/// <filterpriority>1</filterpriority>
		public bool Contains(SmartTreeOptionNode node)
		{
			return this.InnerNodes.Contains(node);
		}


		/// <summary>Determines whether the collection contains a tree node with the specified key.</summary>
		/// <returns>true to indicate the collection contains a <see cref="SmartTreeOptionNode"></see> with the specified key; otherwise, false. </returns>
		/// <param name="key">The name of the <see cref="SmartTreeOptionNode"></see> to search for.</param>
		/// <filterpriority>1</filterpriority>
		public bool ContainsKey(string key)
		{
			return this.InnerNodes.ContainsKey(key);
		}

		/// <summary>Copies the entire collection into an existing array at a specified location within the array.</summary>
		/// <param name="dest">The destination array. </param>
		/// <param name="index">The index in the destination array at which storing begins. </param>
		/// <filterpriority>1</filterpriority>
		public void CopyTo(Array dest, int index)
		{
			this.InnerNodes.CopyTo(dest, index);
		}



		/// <summary>Finds the tree nodes with specified key, optionally searching subnodes.</summary>
		/// <returns>An array of <see cref="SmartTreeOptionNode"></see> objects whose <see cref="P:System.Windows.Forms.TreeNode.Name"></see> property matches the specified key.</returns>
		/// <param name="searchAllChildren">true to search child nodes of tree nodes; otherwise, false. </param>
		/// <param name="key">The name of the tree node to search for.</param>
		/// <filterpriority>1</filterpriority>
		public SmartTreeOptionNode[] Find(string key, bool searchAllChildren)
		{
			TreeNode[] nodeArray1 = this.InnerNodes.Find(key, searchAllChildren);
			SmartTreeOptionNode[] nodeArray2 = new SmartTreeOptionNode[nodeArray1.Length];
			nodeArray1.CopyTo(nodeArray2, 0);
			return nodeArray2;
		}



		/// <summary>Returns the index of the specified tree node in the collection.</summary>
		/// <returns>The zero-based index of the item found in the tree node collection; otherwise, -1.</returns>
		/// <param name="node">The <see cref="SmartTreeOptionNode"></see> to locate in the collection. </param>
		/// <filterpriority>1</filterpriority>
		public int IndexOf(SmartTreeOptionNode node)
		{
			return this.InnerNodes.IndexOf(node);
		}


		/// <summary>Returns the index of the first occurrence of a tree node with the specified key.</summary>
		/// <returns>The zero-based index of the first occurrence of a tree node with the specified key, if found; otherwise, -1.</returns>
		/// <param name="key">The name of the tree node to search for.</param>
		/// <filterpriority>1</filterpriority>
		public int IndexOfKey(string key)
		{
			return this.InnerNodes.IndexOfKey(key);
		}


		/// <summary>Creates a tree node with the specified text and inserts it at the specified index.</summary>
		/// <returns>The <see cref="SmartTreeOptionNode"></see> that was inserted in the collection.</returns>
		/// <param name="index">The location within the collection to insert the node.</param>
		/// <param name="text">The text to display in the tree node.</param>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
		public SmartTreeOptionNode Insert(int index, string text)
		{
			SmartTreeOptionNode node1 = new SmartTreeOptionNode(text);
			this.InnerNodes.Insert(index, node1);
			return node1;
		}


		/// <summary>Inserts an existing tree node into the tree node collection at the specified location.</summary>
		/// <param name="node">The <see cref="SmartTreeOptionNode"></see> to insert into the collection. </param>
		/// <param name="index">The indexed location within the collection to insert the tree node. </param>
		/// <exception cref="T:System.ArgumentException">The node is currently assigned to another <see cref="T:System.Windows.Forms.TreeView"></see>. </exception>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
		public void Insert(int index, SmartTreeOptionNode node)
		{
			this.InnerNodes.Insert(index, node);
		}


		/// <summary>Creates a tree node with the specified text and key, and inserts it into the collection.</summary>
		/// <returns>The <see cref="SmartTreeOptionNode"></see> that was inserted in the collection.</returns>
		/// <param name="key">The name of the tree node.</param>
		/// <param name="index">The location within the collection to insert the node.</param>
		/// <param name="text">The text to display in the tree node.</param>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
		public SmartTreeOptionNode Insert(int index, string key, string text)
		{
			SmartTreeOptionNode node1 = new SmartTreeOptionNode(text);
			node1.Name = key;
			this.InnerNodes.Insert(index, node1);
			return node1;
		}


		/// <summary>Creates a tree node with the specified key, text, and image, and inserts it into the collection at the specified index.</summary>
		/// <returns>The <see cref="SmartTreeOptionNode"></see> that was inserted in the collection.</returns>
		/// <param name="imageIndex">The index of the image to display in the tree node.</param>
		/// <param name="key">The name of the tree node.</param>
		/// <param name="index">The location within the collection to insert the node.</param>
		/// <param name="text">The text to display in the tree node.</param>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
		public SmartTreeOptionNode Insert(int index, string key, string text, int imageIndex)
		{
			SmartTreeOptionNode node1 = new SmartTreeOptionNode(text);
			node1.Name = key;
			node1.ImageIndex = imageIndex;
			this.InnerNodes.Insert(index, node1);
			return node1;
		}


		/// <summary>
		/// Creates a tree node with the specified key, text, and image, and inserts it into the collection at the specified index.
		/// </summary>
		/// <param name="index">The location within the collection to insert the node.</param>
		/// <param name="key">The name of the tree node.</param>
		/// <param name="text">The text to display in the tree node.</param>
		/// <param name="imageKey">The key of the image to display in the tree node.</param>
		/// <returns>
		/// The <see cref="SmartTreeOptionNode"></see> that was inserted in the collection.
		/// </returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public SmartTreeOptionNode Insert(int index, string key, string text, string imageKey)
		{
			SmartTreeOptionNode node1 = new SmartTreeOptionNode(text);
			node1.Name = key;
			node1.ImageKey = imageKey;
			this.InnerNodes.Insert(index, node1);
			return node1;
		}

		/// <summary>
		/// Creates a tree node with the specified key, text, and images, and inserts it into the collection at the specified index.
		/// </summary>
		/// <param name="index">The location within the collection to insert the node.</param>
		/// <param name="key">The name of the tree node.</param>
		/// <param name="text">The text to display in the tree node.</param>
		/// <param name="imageIndex">The index of the image to display in the tree node.</param>
		/// <param name="selectedImageIndex">The index of the image to display in the tree node when it is in a selected state.</param>
		/// <returns>
		/// The <see cref="SmartTreeOptionNode"></see> that was inserted in the collection.
		/// </returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public SmartTreeOptionNode Insert(int index, string key, string text, int imageIndex, int selectedImageIndex)
		{
			SmartTreeOptionNode node1 = new SmartTreeOptionNode(text, imageIndex, selectedImageIndex);
			node1.Name = key;
			this.InnerNodes.Insert(index, node1);
			return node1;
		}

		/// <summary>
		/// Creates a tree node with the specified key, text, and images, and inserts it into the collection at the specified index.
		/// </summary>
		/// <param name="index">The location within the collection to insert the node.</param>
		/// <param name="key">The name of the tree node.</param>
		/// <param name="text">The text to display in the tree node.</param>
		/// <param name="imageKey">The key of the image to display in the tree node.</param>
		/// <param name="selectedImageKey">The key of the image to display in the tree node when it is in a selected state.</param>
		/// <returns>
		/// The <see cref="SmartTreeOptionNode"></see> that was inserted in the collection.
		/// </returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public SmartTreeOptionNode Insert(int index, string key, string text, string imageKey, string selectedImageKey)
		{
			SmartTreeOptionNode node1 = new SmartTreeOptionNode(text);
			node1.Name = key;
			node1.ImageKey = imageKey;
			node1.SelectedImageKey = selectedImageKey;
			this.InnerNodes.Insert(index, node1);
			return node1;
		}

		/// <summary>
		/// Removes a tree node from the tree node collection at a specified index.
		/// </summary>
		/// <param name="index">The index of the <see cref="SmartTreeOptionNode"></see> to remove.</param>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public void RemoveAt(int index)
		{
			this.InnerNodes[index].Remove();
		}


		/// <summary>Removes the tree node with the specified key from the collection.</summary>
		/// <param name="key">The name of the tree node to remove from the collection.</param>
		/// <filterpriority>1</filterpriority>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
		public void RemoveByKey(string key)
		{
			this.InnerNodes.RemoveByKey(key);
		}





		/// <summary>
		/// Removes the specified tree node from the tree node collection.
		/// </summary>
		/// <param name="node">The <see cref="SmartTreeOptionNode"></see> to remove.</param>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public void Remove(SmartTreeOptionNode node)
		{
			node.Remove();
		}




		/// <summary>
		/// Adds the specified node.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		int IList.Add(object node)
		{
			return ((IList)this.InnerNodes).Add(node);
		}

		/// <summary>
		/// Determines whether [contains] [the specified node].
		/// </summary>
		/// <param name="node">The node.</param>
		/// <returns>
		/// 	<c>true</c> if [contains] [the specified node]; otherwise, <c>false</c>.
		/// </returns>
		bool IList.Contains(object node)
		{
			return ((IList)this.InnerNodes).Contains(node);
		}


		/// <summary>
		/// Indexes the of.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		int IList.IndexOf(object node)
		{
			return ((IList)this.InnerNodes).IndexOf(node);
		}



		/// <summary>
		/// Inserts the specified index.
		/// </summary>
		/// <param name="index">The index.</param>
		/// <param name="node">The node.</param>
		void IList.Insert(int index, object node)
		{
			((IList)this.InnerNodes).Insert(index, node);
		}


		/// <summary>
		/// Removes the specified node.
		/// </summary>
		/// <param name="node">The node.</param>
		void IList.Remove(object node)
		{
			((IList)this.InnerNodes).Remove(node);
		}


		/// <summary>
		/// Gets or sets the <see cref="SmartTreeOptionNode"></see> at the specified indexed location in the collection.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="SmartTreeOptionNode"></see> at the specified indexed location in the collection.</returns>
		/// <exception cref="T:System.ArgumentOutOfRangeException">The index value is less than 0 or is greater than the number of tree nodes in the collection. </exception>
		public SmartTreeOptionNode this[int index]
		{
			get
			{
				return this.InnerNodes[index] as SmartTreeOptionNode;
			}
			set
			{
				this.InnerNodes[index] = value;
			}
		}

		/// <summary>
		/// Gets the tree node with the specified key from the collection.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="SmartTreeOptionNode"></see> with the specified key.</returns>
		public SmartTreeOptionNode this[string key]
		{
			get
			{
				return this.InnerNodes[key] as SmartTreeOptionNode;
			}
		}

		/// <summary>
		/// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe).
		/// </summary>
		/// <value></value>
		/// <returns>true if access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe); otherwise, false.</returns>
		bool ICollection.IsSynchronized
		{
			get
			{
				return ((ICollection)this.InnerNodes).IsSynchronized;
			}
		}

		/// <summary>
		/// Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.
		/// </summary>
		/// <value></value>
		/// <returns>An object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.</returns>
		object ICollection.SyncRoot
		{
			get
			{
				return this.InnerNodes;
			}
		}

		/// <summary>
		/// Gets a value indicating whether the <see cref="T:System.Collections.IList"></see> has a fixed size.
		/// </summary>
		/// <value></value>
		/// <returns>true if the <see cref="T:System.Collections.IList"></see> has a fixed size; otherwise, false.</returns>
		bool IList.IsFixedSize
		{
			get
			{
				return ((IList)this.InnerNodes).IsFixedSize;
			}
		}

		/// <summary>
		/// Gets or sets the <see cref="Object"/> at the specified index.
		/// </summary>
		/// <value></value>
		object IList.this[int index]
		{
			get
			{
				return this.InnerNodes[index];
			}
			set
			{
				this.InnerNodes[index] = (SmartTreeOptionNode)value;
			}
		}



		#endregion

		#region IEnumerable Members

		/// <summary>
		/// Returns an enumerator that iterates through a collection.
		/// </summary>
		/// <returns>
		/// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
		/// </returns>
		public IEnumerator GetEnumerator()
		{
			return this.InnerNodes.GetEnumerator();
		}

		#endregion
	}
}
